package business.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Required;
import org.springframework.transaction.annotation.Transactional;

import vo.Template;
import business.TemplateService;
import dao.TemplateDAO;

public class TemplateServiceImpl implements TemplateService {

	private TemplateDAO templateDao;

	public List<Template> getAllTemplates() {
		return templateDao.findAll();
	}

	public List<Template> getBySourceId(long sourceId) {
		return templateDao.findBySourceId(sourceId);
	}

	public long getTotalCount() {
		return templateDao.findTotalCount();
	}

	public long getTotalCount(long sourceId) {
		return templateDao.findTotalCount(sourceId);
	}

	public List<Template> getBySourceId(int start, int pageSize, long sourceId) {
		return templateDao.findBySourceId(start, pageSize, sourceId);
	}

	@Required
	public void setTemplateDao(TemplateDAO templateDao) {
		this.templateDao = templateDao;
	}

	@Transactional
	public void addTemplate(String name) {
		Template e = new Template();
		templateDao.create(e);
	}

	@Transactional
	public void addTemplate(Template template) {
		templateDao.create(template);
	}

	@Transactional
	public Template getById(long id) {
		return templateDao.getById(id);
	}

	@Transactional
	public void update(long id) {
		templateDao.update(id);
	}

	@Transactional
	public void delete(long id) {// 真正删除
		templateDao.delete(id);
	}

}